<template>
	<el-card shadow="hover">
		<el-form :model="queryParams" ref="queryFormRef" :inline="true" v-show="showSearch">
			<el-form-item label="付款时间" prop="pay_time">
        <el-date-picker
          v-model="queryParams.pay_time"
          type="date"
          placeholder="选择付款时间"
          clearable
          value-format="YYYY-MM-DD"
        >
        </el-date-picker>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="onQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" @click="onResetQuery">重置</el-button>
			</el-form-item>
		</el-form>
		<el-row :gutter="10" class="top-block mb8">
			<right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
		</el-row>
		<el-table :data="tableList" v-loading="loading">
			<el-table-column label="付款时间" align="center" prop="pay_time" />
			<el-table-column label="应发货时间" align="center" prop="send_time" />
			<el-table-column label="应发货订单数" align="center">
        <template #default="{ row }">
          <el-link type="primary" @click="onOpen(row)">{{ row.send_num }}</el-link>
        </template>
      </el-table-column>
			<el-table-column label="实际发货订单数" align="center" prop="reality_send_num">
				<template #default="{ row }">
          <el-link type="primary" @click="onOpen(row)">{{ row.reality_send_num }}</el-link>
        </template>
			</el-table-column>
			<!-- <el-table-column label="操作" align="center" fixed="right">
				<template #default="{ row }">
				</template>
			</el-table-column> -->
		</el-table>
		<pagination-component
			v-show="total > 0"
			:total="total"
			v-model:page="queryParams.pageNum"
			v-model:limit="queryParams.pageSize"
			@pagination="getList"
		/>

		<GoodDeliveryStatisticsDialog ref="goodDeliveryStatisticsRef" />
	</el-card>
</template>

<script lang="ts">
import { onMounted, reactive, ref, toRefs } from 'vue';
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus';
import { statisticsGoodsSendApi } from '/@/api/admin1';
import { handleDownloadByName } from '/@/utils/utils';
import GoodDeliveryStatisticsDialog from './dialog/goodDeliveryStatisticsDialog.vue';

const StatisticsGoodsSendApi = statisticsGoodsSendApi();
export default {
	name: 'goodDeliveryStatistics',
	components: {
		GoodDeliveryStatisticsDialog,
	},
	setup() {
		const queryFormRef = ref(null);

		const goodDeliveryStatisticsRef = ref(null);

		const state = reactive({
			queryParams: {
				pay_time: '',
				pageNum: 1,
				pageSize: 10,
			},
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			showSearch: true,
			tableList: [],
			loading: false,
			total: 0,
		});

		onMounted(() => {
			getList();
		});

		/********** 点击事件(on开头) **********/
		// 搜索
		const onQuery = () => {
			state.queryParams.pageNum = 1;
			getList();
		};
		// 重置
		const onResetQuery = () => {
			(queryFormRef.value as any)?.resetFields();
			onQuery();
		};
		// 打开
		const onOpen = (row) => {
			(goodDeliveryStatisticsRef.value as any)?.openDialog({ pay_time: row.pay_time })
		};
		/********** 方法事件 **********/
		const getList = () => {
			state.loading = true;
			_statisticsGoodsSendList(state.queryParams);
		};

		/********** 网络事件 **********/
		// 商品发货统计
		const _statisticsGoodsSendList = (_data: object) => {
			StatisticsGoodsSendApi.statisticsGoodsSendList(_data)
				.then((res: any) => {
					console.log(res);
					state.tableList = res.data.list;
					state.total = res.data.total;
					state.loading = false;
				})
				.catch(() => (state.loading = false));
		};
		
		return {
			queryFormRef,
			goodDeliveryStatisticsRef,
			onOpen,
			onQuery,
			onResetQuery,
			getList,
			...toRefs(state),
		};
	},
};
</script>

<style lang="scss" scoped></style>
